﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Com.Mapabc.Maps.Api.BaseTypes;
using Microsoft.Phone.Controls;

namespace MapABCAPI_WP7.Samples
{
    public partial class MapControl : PhoneApplicationPage
    {
        public MapControl()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 放大/缩小地图
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ZoomIn(object sender, GestureEventArgs e)
        {
            Hidden();
            button1.Visibility = System.Windows.Visibility.Visible;//button1可见
            button2.Visibility = System.Windows.Visibility.Visible;//button2可见
            Pivot.SelectedIndex = 1;//显示效果
        }
        private void mapZoomIn(object sender, RoutedEventArgs e)
        {
            map.ZoomIn();//以当前中心点为焦点放大地图
        }
        private void ZoomOut(object sender, GestureEventArgs e)
        {
            Hidden();
            button2.Visibility = System.Windows.Visibility.Visible;//button2可见
            Pivot.SelectedIndex = 1;//显示效果
        }
        private void mapZoomOut(object sender, RoutedEventArgs e)
        {
            map.ZoomOut();//以当前中心点为焦点缩小地图
        }
        /// <summary>
        /// 设置地图中心点
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SetCenter(object sender, GestureEventArgs e)
        {
            Hidden();
            mapLngX.Visibility = System.Windows.Visibility.Visible;
            mapLatY.Visibility = System.Windows.Visibility.Visible;
            double centerLng = double.Parse(mapLngX.Text);
            double centerLat = double.Parse(mapLatY.Text);
            map.Center = new MLngLat(centerLng, centerLat);
            Pivot.SelectedIndex = 1;//显示效果
        }
        /// <summary>
        /// 移图方法
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PanBy(object sender, GestureEventArgs e)
        {
            Hidden();
            panX.Visibility = System.Windows.Visibility.Visible;
            panY.Visibility = System.Windows.Visibility.Visible;
            button3.Visibility = System.Windows.Visibility.Visible;
            Pivot.SelectedIndex = 1;//显示效果
        }
        private void mapPanBy(object sender, RoutedEventArgs e)
        {
            double x = double.Parse(panX.Text);
            double y = double.Parse(panY.Text);
            map.PanBy(new Point(x, y));//地图滑动按指定的像素距离。
        }
        /// <summary>
        /// 保存地图状态
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SavePosition(object sender, GestureEventArgs e)
        {
            Hidden();
            button4.Visibility = System.Windows.Visibility.Visible;
            button5.Visibility = System.Windows.Visibility.Visible;
            Pivot.SelectedIndex = 1;//显示效果
        }
        private void mapSavePosition(object sender, RoutedEventArgs e)
        {
            map.SavePosition();// 保存地图当前中心点位置和zoom级别，只是存储下来，并不能被调用返回存储值。
        }

        private void mapReturnToSavedPosition(object sender, RoutedEventArgs e)
        {
            map.ReturnToSavedPosition();// 返回到由上次保存的地图中心点位置和zoom级别所确定的视野范围状态。
        }
        /// <summary>
        /// 设置地图状态
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void setToolBar(object sender, GestureEventArgs e)
        {
            Hidden();
            button6.Visibility = System.Windows.Visibility.Visible;
            button7.Visibility = System.Windows.Visibility.Visible;
            Pivot.SelectedIndex = 1;//显示效果
        }
        private void setToolBarHide(object sender, RoutedEventArgs e)
        {
            map.ToolBar = Visibility.Collapsed;
        }

        private void setToolBarShow(object sender, RoutedEventArgs e)
        {
            map.ToolBar = Visibility.Visible;
        }
        /// <summary>
        /// 是否允许拖动地图
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DragEnabled(object sender, GestureEventArgs e)
        {
            Hidden();
            button8.Visibility = System.Windows.Visibility.Visible;
            button9.Visibility = System.Windows.Visibility.Visible;
            Pivot.SelectedIndex = 1;//显示效果
        }
        private void IsDragEnabledTrue(object sender, RoutedEventArgs e)
        {
            map.DragEnabled = true;//允许地图拖动
        }

        private void IsDragEnabledFalse(object sender, RoutedEventArgs e)
        {
            map.DragEnabled = false;//禁止地图拖动
        }
        /// <summary>
        /// 是否允许缩放地图
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ZoomEnabled(object sender, GestureEventArgs e)
        {
            Hidden();
            button10.Visibility = System.Windows.Visibility.Visible;
            button11.Visibility = System.Windows.Visibility.Visible;
            Pivot.SelectedIndex = 1;//显示效果
        }
       
        private void IsZoomEnabledTrue(object sender, RoutedEventArgs e)
        {
            map.ZoomEnabled = true;
        }

        private void IsZoomEnabledFalse(object sender, RoutedEventArgs e)
        {
            map.ZoomEnabled = false;
        }
        private void Hidden()
        {
            button1.Visibility = System.Windows.Visibility.Collapsed;
            button2.Visibility = System.Windows.Visibility.Collapsed;
            mapLngX.Visibility = System.Windows.Visibility.Collapsed;
            mapLatY.Visibility = System.Windows.Visibility.Collapsed;
            panX.Visibility = System.Windows.Visibility.Collapsed;
            panY.Visibility = System.Windows.Visibility.Collapsed;
            button3.Visibility = System.Windows.Visibility.Collapsed;
            button4.Visibility = System.Windows.Visibility.Collapsed;
            button5.Visibility = System.Windows.Visibility.Collapsed;
            button6.Visibility = System.Windows.Visibility.Collapsed;
            button7.Visibility = System.Windows.Visibility.Collapsed;
            button8.Visibility = System.Windows.Visibility.Collapsed;
            button9.Visibility = System.Windows.Visibility.Collapsed;
            button10.Visibility = System.Windows.Visibility.Collapsed;
            button11.Visibility = System.Windows.Visibility.Collapsed;
        }
        /// <summary>
        /// 重写后退键
        /// </summary>
        /// <param name="e"></param>
        protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
        {
            if (Pivot.SelectedIndex == 1)
            {
                e.Cancel = true;
                Pivot.SelectedIndex = 0;
            }
        }       
    } 
}